/*初始化数据表格*/
function initTable() {
    var url=getBasePath()+'/mdm/dict/getListData.json';
    var tableId="table_data";
    $("#"+tableId).dataTable().fnDestroy();
    json = {};
    json.showLineNuber = false;
    json.id = tableId;
    json.pagesize=2;
    json.url = url ;
    json.param = [
        {"name": "dictType", "value": $.trim($("#dictType").val())},
        {"name": "dictCode", "value": $.trim($("#dictCode").val())},
        {"name": "dictName", "value": $.trim($("#dictName").val())},
        {"name": "dictDesc", "value": $.trim($("#dictDesc").val())},
        {"name": "orderId", "value": $.trim($("#orderId").val())},
        {"name": "status", "value": $.trim($("#status").val())},
    ];
    json.columns = [
        {
            "mData": "dictCode", "sWidth": "15%", "sClass": "text-center",
            "mRender": function (data, type, row) {
                if (data) {
					var detailStr="<a class='icondatatable' vb='详情' href=\"#\" onclick='toDetailPage(\""+data+"\");'><i class=\"icon-detail\"></i></a>";
                    var editStr="<a class='icondatatable' vb='修改' href=\"#\" onclick='toEditDict(\""+data+"\");'><i class=\"icon-edit\"></i></a>";
                    var delStr="<a class='icondatatable' vb='删除' href=\"#\"  onclick='deleteDict(\""+data+"\");'><i class=\"icon-bin\"></i></a>";

                    return detailStr+editStr+delStr;
                }
            }
        },
        {"mData": "dictType", "sClass": "text-center"},
        {"mData": "dictCode", "sClass": "text-center"},
        {"mData": "dictName", "sClass": "text-center"},
        {"mData": "dictDesc", "sClass": "text-center"},
        {"mData": "orderId", "sClass": "text-center"},
        {"mData": "status", "sClass": "text-center"},
    ];
    var oTable1 = TableManaged(json).init();
}
/*查询数据*/
function doQuery(){
    initTable();
}


/*重置查询条件*/
function resetQueryForm(){
	$("#dictType").val('');
	$("#dictCode").val('');
	$("#dictName").val('');
	$("#dictDesc").val('');
	$("#orderId").val('');
	$("#status").val('');
}

/*删除数据*/
function deleteDict(dictCode){
    var _url=getBasePath()+'/mdm/dict/delete.json';
    $.Confirm('你确定要删除这条记录吗？','',function(){
        var dict={};
        dict.dictCode=dictCode;
        $.ajax({
            url:_url,
            type:'POST',
            dataType:'json',
            contentType:'application/json',
            data:JSON.stringify(dict),
            success:function(data){
                if(data.status==200){
                    $.Success('删除成功',doQuery);
                }else{
                    var msg = data.message || "删除数据字典数据发生错误";
                    $.Error(msg,'',null);
                }
            }
        });
    });

}

/*跳转编辑数据页面*/
function toEditDict(dictCode){
    var _url=getBasePath()+'/mdm/dict/toEdit.htm?dictCode='+dictCode;
    location.href=_url;
}

/*编辑数据*/
function editDict(){
    $validator =$("#dict_edit_form").validator('isFormValid');
    if(!$validator){
        return;
    }
    var _url=getBasePath()+'/mdm/dict/edit.json';
    var dict={};
	dict.dictType=$("#dictType").val();
	dict.dictCode=$("#dictCode").val();
	dict.dictName=$("#dictName").val();
	dict.dictDesc=$("#dictDesc").val();
	dict.orderId=$("#orderId").val();
	dict.status=$("#status").val();

    $.ajax({
        url:_url,
        type:'POST',
        dataType:'json',
        contentType:'application/json',
        data:JSON.stringify(dict),
        success:function(data){
            if(data.status==200){
                $.Success('该记录已提交成功!',gotoListPage);
            }else{
                var msg = data.message || "编辑数据字典数据发生错误";
                $.Error(msg,'',null);
            }

        },
        error:function(data){
            JSON.stringify(data);
        }
    });
}

/*跳转新增数据页面*/
function toAddDict(){
    var _url=getBasePath()+'/mdm/dict/toAdd.htm';
    location.href=_url;
}

/*新增数据*/
function saveDict(){
    $validator =$("#dict_add_form").validator('isFormValid');
    if(!$validator){
        return;
    }
    var _url=getBasePath()+'/mdm/dict/add.json';
    var dict={};
	dict.dictType=$("#dictType").val();
	dict.dictCode=$("#dictCode").val();
	dict.dictName=$("#dictName").val();
	dict.dictDesc=$("#dictDesc").val();
	dict.orderId=$("#orderId").val();
	dict.status=$("#status").val();
    
    $.ajax({
        url:_url,
        type:'POST',
        dataType:'json',
        contentType:'application/json',
        data:JSON.stringify(dict),
        success:function(data){
            if(data.status==200){
                $.Success('该记录已提交成功!',gotoListPage);
            }else{
                var msg = data.message || "新增数据字典数据发生错误";
                $.Error(msg,'',null);
            }
        }
    });
}

/*跳转数据列表页面*/
function gotoListPage(){
    location.href=getBasePath()+'/mdm/dict/list.htm';
}





